package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsRegion;
import com.qf.service.RegionService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @author Wy
 * @version V1.0
 * @Project MavenDemo
 * @Package com.qf.controller
 * @Description:
 * @Date 2022/6/21 10:18
 */
@RestController
@CrossOrigin("*")
@RequestMapping("/region")
public class RegionController {

    @Autowired
    private RegionService service;

    @RequestMapping("/list")
    public  Object list(String name, String code,
                        @RequestParam(defaultValue = "1")Integer page,
                        @RequestParam(defaultValue = "10")Integer limit){
        IPage<DtsRegion> page1 = service.queryRegionPage(name, code, page, limit);

        List<DtsRegion> records = page1.getRecords();

        long total = page1.getTotal();
        HashMap<String, Object> data = new HashMap<>();
        data.put("total", total);
        data.put("items", records);


        return ResponseUtil.ok(data);
    }


}
